package com.demo.test.service.impl;

import com.demo.test.service.IRedisService;
import com.demo.test.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 测试
 */
@Service
public class RedisServiceImpl implements IRedisService {
    @Autowired
    RedisUtils redisUtils;

    @Override
    public String test() {
        boolean lock = redisUtils.getLock("lockId", 10 * 1000);
        if (lock) {
            System.out.println("执行任务");
            redisUtils.releaseLock("lockId");
        } else {
            System.out.println("没有抢到锁");
        }
        return "执行redis任务成功";
    }
}
